import axios from 'axios';
import buildPaginationQueryOpts from '@/shared/sort/sorts';
<%_ if (databaseTypeCassandra) { _%>
import {Authority} from '@/shared/security/authority'
<%_ } _%>
import { type IUser } from '@/shared/model/user.model';

export default class UserManagementService {

  get(userId: string): Promise<any> {
    return axios.get(`api/admin/users/${userId}`);
  }

  create(user: IUser): Promise<any> {
    return axios.post('api/admin/users', user);
  }

  update(user: IUser): Promise<any> {
    return axios.put('api/admin/users', user);
  }

  remove(userId: <%- user.primaryKey.tsType %>): Promise<any> {
    return axios.delete(`api/admin/users/${userId}`);
  }

  retrieve(<%_ if (!databaseTypeCassandra) { _%>req?: any <%_ } _%>): Promise<any> {
    return axios.get(`api/admin/users<%_ if (!databaseTypeCassandra) { _%>?${buildPaginationQueryOpts(req)}<%_ } _%>`);
  }

  retrieveAuthorities(): Promise<any> {
<%_ if (!databaseTypeCassandra) { _%>
    return axios.get('api/authorities').then(response => {
      response.data = response.data.map(authority => authority.name);
      return response;
    });
<%_ } else { _%>
    return Promise.resolve([Authority.USER, Authority.ADMIN]);
<%_ } _%>
  }
}
